package com.sin.j2me.wihd.communi;

import com.sin.j2me.framework.SinUtil;
import com.sin.j2me.wihd.FrameWork;
import com.sin.j2me.wihd.common.Protocol;
import com.sin.j2me.wihd.model.Param;
import com.sin.j2me.wihd.model.Response;

public class InterfaceRequest {
	public static String getResponseString(String itfname, Param pam){
		String res = "";
		StringBuffer sb = new StringBuffer();
		sb.append(Protocol.URL);
		sb.append('?');
		
		sb.append(Protocol.P_INTERFACE);
		sb.append('=');
		sb.append(itfname);
		sb.append('&');
		
		int id = FrameWork.UO.getUserid();
		if(id!=0){
			sb.append(Protocol.P_USERID);
			sb.append('=');
			sb.append(id);
			sb.append('&');
		}
		
		String tk = FrameWork.UO.getToken();
		if(tk != null && tk.length()>0){
			sb.append(Protocol.P_TOKEN);
			sb.append('=');
			sb.append(FrameWork.UO.getToken());
			sb.append('&');
		}
		
		for(int i=0; i<pam.size(); ++i){
			sb.append(pam.getPam(i));
			sb.append('&');
		}
		
		String url = sb.toString();
//		System.out.println("URL:"+url);
		res = SinUtil.HttpGet(url);
//		System.out.println("RES:"+res);
		return res;
	}
	
	public static Response getResponse(String itfname, Param pam){
		String json = getResponseString(itfname, pam);
		return new Response(json);
	}
}
